package org.jash.sportnews2109.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import dagger.hilt.android.AndroidEntryPoint
import org.jash.common.mvvm.BaseActivity
import org.jash.common.mvvm.BaseViewModel
import org.jash.common.token
import org.jash.sportnews2109.R
import org.jash.sportnews2109.databinding.ActivityMainBinding

@Route(path = "/news/main")
@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, BaseViewModel>() {

    override fun initView() {
        binding.navigation.setOnItemSelectedListener {
            if(token == null && it.itemId in listOf(R.id.bookmark, R.id.mine)) {
                ARouter.getInstance().build("/news/login").navigation()
                return@setOnItemSelectedListener false
            }
            supportFragmentManager.beginTransaction()
                .replace(R.id.content, ARouter.getInstance().build(
                    when(it.itemId) {
                        R.id.video ->  "/news/video"
                        R.id.bookmark ->  "/news/bookmark"
                        R.id.mine ->  "/news/mine"
                        else -> "/news/home"
                    }
                ).navigation() as Fragment)
                .commit()
            true
        }
        binding.navigation.selectedItemId = R.id.home
    }

    override fun initData() {
    }
}